package com.lun.swordtowardoffer2.c02;

public class NumSubarrayProductLessThanK {

	public int numSubarrayProductLessThanK(int[] nums, int k) {
		long product = 1;
		
		int p1 = 0, count = 0;
		for(int p2 = 0; p2 < nums.length; p2++) {
			product *= nums[p2];
			while(p1 <= p2 && product >= k) {
				product /= nums[p1++];
			}
			
			count += (p1 <= p2 ? p2 - p1 + 1 : 0); 
		}
		
		return count;
	}
	
}

